package br.com.fafica.sisape.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import java.awt.Font;
import java.util.ArrayList;

import javax.swing.SwingConstants;
import javax.swing.JComboBox;
import javax.swing.JButton;

import br.com.fafica.sisape.control.ControllerAgendas;
import br.com.fafica.sisape.control.ControllerClinica;
import br.com.fafica.sisape.control.ControllerMedico;
import br.com.fafica.sisape.control.ControllerUsuario;
import br.com.fafica.sisape.model.Paciente;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class TelaClinicaNovoExame extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TelaMedicoNovaConsulta frame = new TelaMedicoNovaConsulta();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TelaClinicaNovoExame() {
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(255, 255, 255));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("Paciente:");
		label.setHorizontalAlignment(SwingConstants.RIGHT);
		label.setForeground(new Color(0, 0, 128));
		label.setFont(new Font("Tahoma", Font.PLAIN, 14));
		label.setBounds(34, 45, 59, 15);
		contentPane.add(label);
		
		final JComboBox comboPaciente = new JComboBox();
		comboPaciente.setBounds(96, 38, 293, 26);
		contentPane.add(comboPaciente);
		ControllerUsuario controleUser = new ControllerUsuario();
		ArrayList listaUsuario = new ArrayList<>();
		listaUsuario = controleUser.listarUsuarios();
		comboPaciente.addItem("");
		Paciente p;
		for(int i = 0; i < listaUsuario.size(); i++){
			p = (Paciente) listaUsuario.get(i);
			comboPaciente.addItem(p.getNome());
		}
		
		JLabel lblData = new JLabel("Data:");
		lblData.setHorizontalAlignment(SwingConstants.RIGHT);
		lblData.setForeground(new Color(0, 0, 128));
		lblData.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblData.setBounds(34, 102, 59, 15);
		contentPane.add(lblData);
		
		
		final JComboBox comboData = new JComboBox();
		comboData.setBounds(96, 95, 293, 26);
		contentPane.add(comboData);
		ControllerAgendas control = new ControllerAgendas();
		ArrayList<String> listaData = new ArrayList<>();
		listaData = control.carregaDia();
		comboData.addItem("");
		String dia;
		for(int i= 0; i < listaData.size(); i++){
			dia = listaData.get(i);
			comboData.addItem(dia);
		}
		
		JLabel lblHora = new JLabel("Hora:");
		lblHora.setHorizontalAlignment(SwingConstants.RIGHT);
		lblHora.setForeground(new Color(0, 0, 128));
		lblHora.setFont(new Font("Tahoma", Font.PLAIN, 14));
		lblHora.setBounds(34, 159, 59, 15);
		contentPane.add(lblHora);
		
		final JComboBox comboHora = new JComboBox();
		comboHora.setBounds(96, 152, 293, 26);
		contentPane.add(comboHora);
		ControllerAgendas controleHora = new ControllerAgendas();
		ArrayList<String> listaHora = new ArrayList<>();
		listaData = controleHora.carregaHora();
		comboHora.addItem("");
		String hora;
		for(int i= 0; i < listaData.size(); i++){
			hora = listaData.get(i);
			comboHora.addItem(hora);
		}
		
		JButton btnMarcar = new JButton("Marcar");
		btnMarcar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				String nome = (String) comboPaciente.getSelectedItem();
				String data = (String) comboData.getSelectedItem();
				String hora = (String) comboHora.getSelectedItem();
				
				ControllerAgendas control = new ControllerAgendas();
				control.inserirAgendaExame(data, hora, nome, ControllerClinica.clinicaLogada.getNome());
				dispose();
			}
		});
		btnMarcar.setForeground(new Color(0, 0, 128));
		btnMarcar.setFont(new Font("Tahoma", Font.PLAIN, 12));
		btnMarcar.setBounds(173, 209, 89, 23);
		contentPane.add(btnMarcar);
	}

}
